package cn.tedu.smartmarketing.business.service.impl;

import cn.tedu.smartmarketing.admin.pojo.entity.Checks;
import cn.tedu.smartmarketing.business.mapper.BusinessMapper;
import cn.tedu.smartmarketing.business.pojo.dto.*;
import cn.tedu.smartmarketing.business.pojo.entity.Activity;
import cn.tedu.smartmarketing.business.pojo.entity.Business;
import cn.tedu.smartmarketing.business.pojo.entity.commodity;
import cn.tedu.smartmarketing.business.pojo.vo.BusinessVO;
import cn.tedu.smartmarketing.business.pojo.vo.CommentVO;
import cn.tedu.smartmarketing.business.pojo.vo.commodityVo;
import cn.tedu.smartmarketing.business.service.BusinessService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class BusinessServiceImpl implements BusinessService {
    @Autowired
    BusinessMapper businessMapper;


    @Override
    public void createActivity(ActivityCreateParam activityCreateParam) {
        log.debug("创建活动业务：{}",activityCreateParam);
        Activity activity = new Activity();
        BeanUtils.copyProperties(activityCreateParam,activity);
        activity.setActivityDate(new Date());
        activity.setEndTime(new Date());
        businessMapper.createActivity(activity);
    }
    @Override
    public void reg(BusinessRegParam businessRegParam) {
        log.debug("商家入驻" + businessRegParam);
        Business business = new Business();
        BeanUtils.copyProperties(businessRegParam, business);
        business.setBusinessStatus(0);
        business.setEntryTime(new Date());
        businessMapper.insert(business);
    }

    @Override
    public List<BusinessVO> list(BusinessQuery businessQuery) {
        log.debug("商家列表" +businessQuery);
        List<BusinessVO> businessVOS = businessMapper.list(businessQuery);
        return businessVOS;
    }

    @Override
    public BusinessVO detail(Integer businessId) {
        log.debug("商家详细信息业务" +businessId);
        BusinessVO businessVO = businessMapper.select(businessId);
        return businessVO;
    }
    @Override
    public List<CommentVO> listComment(Integer productId) {
        log.debug("商品评论列表查询{}", productId);
        List<CommentVO> list = businessMapper.listComment(productId);
        return list;
    }

    @Override
    public void applyChecks(BusinessChecksParam businessChecksParam) {
        log.debug("商家申请审核{}", businessChecksParam);
        Checks checks = new Checks();
        BeanUtils.copyProperties(businessChecksParam,checks);
        checks.setApplicationTime(new Date());
        checks.setAuditStatus(2);
        businessMapper.applyChecks(checks);
    }

    @Override
    public void publishProduct(Addcommodity addcommodity) {
        log.info("商品信息："+addcommodity);
        commodity commodity = new commodity();
        BeanUtils.copyProperties(addcommodity,commodity);
        commodity.setCreate_time(new Date());
        businessMapper.insert2(commodity);
        log.info("发布商品成功");
    }

    @Override
    public List<commodityVo> queryProduct(commodityQuery commodityQuery) {
        List<commodityVo> list = businessMapper.queryProduct(commodityQuery);
        log.info("查询商品成功{}",list);
        return list;
    }
}
